package com.springboot.redis.demo;

/**
 * 基于 Hyperloglog 对网站进行垃圾数据进行过滤
 *
 * @author: zr
 * @date: 2021-11-17
 */
public class GarbageContentDemo extends RedisClient {

    /**
     * Redis key
     */
    public static String KEY = "hyperloglog_content";

    /**
     * 判断内容是否是垃圾内容
     *
     * @param
     * @return
     * @throws
     * @date 2021-11-17
     */
    public static boolean isGarbageContent(String content) {
        Long result = jedis.pfadd(KEY, content);
        return result == null ? false : result.equals(0L);
    }

    public static void main(String[] args) {

        String content = "正常的内容";

        System.out.println("是否为垃圾内容：" + (isGarbageContent(content) ? "是" : "否"));

        String garbageContent = "垃圾内容";

        System.out.println("是否为垃圾内容：" + (isGarbageContent(garbageContent) ? "是" : "否"));

        System.out.println("是否为垃圾内容：" + (isGarbageContent(garbageContent) ? "是" : "否"));

    }
}
